package com.zzjson.io.nio.buffer;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

import static com.zzjson.io.nio.FilePathConstans.RANDOMPATH;


/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : cn.zzjson.io.nio.buffer</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年03月26日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class MappedBuffer {
    static private final int start = 0;
    static private final int size = 1024;


    public static void main(String[] args) {
        try {
            RandomAccessFile randomAccessFile = new RandomAccessFile(RANDOMPATH, "rw");
            FileChannel fc = randomAccessFile.getChannel();
            MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, start, size);
            mbb.put(0, (byte) 97);
            mbb.put(1023, (byte) 122);
            randomAccessFile.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}